package com.my.learn.lock;

import org.openjdk.jol.info.ClassLayout;

public class Lock01 {

    public static void main(String[] args) throws InterruptedException {
        Object o = new Object();
        Thread.sleep(5000);
        Object k = new Object();
        /*  对象由16byte存储，对象头占12byte，实例数据占1byte，对齐填充站3byte，
         *  其中对象头中运行时元数据占8byte，类型指针占4byte，运行时元数据8byte中第1个byte存储分带年龄，
         *  偏向锁标识，对象状态，第2-5个byte为hashCode值和1bit存储unse，第6-8byte为unuse,
         */
        System.out.println(ClassLayout.parseInstance(k).toPrintable());
        synchronized (o){
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }
        synchronized (k){
            System.out.println(ClassLayout.parseInstance(k).toPrintable());
        }
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
    }

}
